/************************************************
* 文件描述: 程序首页内容类
* 待完善:
* 待优化:
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*************************************************/
#include "main_page.h"
#include "globaldata.h"
/************************************************
* 函数名称：MainPage
* 功能描述：构造函数
* 输入参数：程序参数类
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
const QString BTN_TO_LABEL_STYLE = "QPushButton{border:0px;border-radius:4px;background:transparent;}"
                                   "QPushButton:Hover{border:0px;border-radius:4px;background:transparent;}"
                                   "QPushButton:Pressed{border:0px;border-radius:4px;background:transparent;}";
MainPage::MainPage(QWidget *parent):
    QWidget(parent)
{
    m_pKylinPic = nullptr;
    m_pMoreInfoLink_1 = nullptr;
    m_pMoreInfoLink_2 = nullptr;
    m_pMoreInfoLink_3 = nullptr;
    m_pPageTitle = nullptr;

    m_pOnline = nullptr;
    m_pOnline_1 = nullptr;
    m_pOnline_2 = nullptr;
    m_pOnline_3 = nullptr;

    m_pTelphone = nullptr;
    m_pTelphone_1 = nullptr;
    m_pTelphone_2 = nullptr;
    m_pTelphone_3 = nullptr;

    m_pMail = nullptr;
    m_pMail_1 = nullptr;
    m_pMail_2 = nullptr;
    m_pMail_3 = nullptr;

    m_pWeChat = nullptr;
    m_pWeChat_1 = nullptr;
    m_pWeChat_2 = nullptr;
    m_pWeChat_3 = nullptr;

    m_pDIY = nullptr;
    m_pDIY_1 = nullptr;
    m_pDIY_2 = nullptr;
    m_pDIY_3 = nullptr;

    this->setWindowTitle("main_page");
    initPageLocation();
}
/************************************************
* 函数名称：initPageLocation
* 功能描述：页面布局函数
* 输入参数：无
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MainPage::initPageLocation()
{
    m_pKylinPic = new QLabel;
    m_pKylinPic->setFixedSize(700,331);
    m_pKylinPic->setStyleSheet("border-image:url(:/data/banner.png);border:0px;");

    QPalette peMid;
    QColor colorMid = palette().color(QPalette::Mid);
    qDebug() << QString("rgba:%1,%2,%3").arg(colorMid.red()).arg(colorMid.green()).arg(colorMid.blue());
    peMid.setColor(QPalette::Text,colorMid);

    m_pMoreInfoLink_1 = new QLabel;
    m_pMoreInfoLink_1->adjustSize();
    m_pMoreInfoLink_1->setText(tr("Click "));
    m_pMoreInfoLink_1->setPalette(peMid);

    m_pMoreInfoLink_2 = new QLabel;
    m_pMoreInfoLink_2->adjustSize();
    m_pMoreInfoLink_2->setCursor(QCursor(Qt::PointingHandCursor));
    m_pMoreInfoLink_2->setText(tr("to know more about support"));
    m_pMoreInfoLink_2->installEventFilter(this);

    QPalette peHighlight;
    QColor colorHighlight = palette().color(QPalette::Highlight);
    qDebug() << QString("rgba:%1,%2,%3").arg(colorHighlight.red()).arg(colorHighlight.green()).arg(colorHighlight.blue());
    peHighlight.setColor(QPalette::Text,colorHighlight);

    m_pMoreInfoLink_2->setPalette(peHighlight);

    m_pMoreInfoLink_3 = new QLabel;
    m_pMoreInfoLink_3->adjustSize();
    m_pMoreInfoLink_3->setText(tr("，to KylinOS Official Web"));
    m_pMoreInfoLink_3->setPalette(peMid);

    m_pPageTitle = new QLabel;
    m_pPageTitle->adjustSize();
    m_pPageTitle->setText(tr("You can get your answers through the ways below"));//"用户可通过以下方式寻求技术支持和服务");
    m_pPageTitle->setAlignment(Qt::AlignHCenter);
    m_pPageTitle->setPalette(peMid);

    m_pOnline_1 = new IconBtn("address-book-new-symbolic");
    m_pOnline_1->setIconSize(QSize(16,16));
    m_pOnline_1->setFixedSize(QSize(16,16));

    m_pOnline_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);//不响应鼠标事件，直接穿透
    m_pOnline_1->setProperty("useIconHighlightEffect", 0x8);
//    m_pOnline_1->setIcon(QIcon::fromTheme("address-book-new-symbolic"));

    m_pOnline_2 = new QLabel;
    m_pOnline_2->adjustSize();
    m_pOnline_2->setText(tr("Official WeChat"));//"企业微信");
    m_pOnline_2->setAlignment(Qt::AlignLeft);
    m_pOnline_2->setAlignment(Qt::AlignVCenter);
    m_pOnline_2->setAttribute(Qt::WA_TransparentForMouseEvents);

    m_pOnline_3 = new QLabel;
    m_pOnline_3->adjustSize();
    m_pOnline_3->setText(tr("Add our Team's WeChat\n Get an online response."));//"用户通过微信添加服务与支持团队成员\n企业微信号，寻求在线响应");
    m_pOnline_3->setAlignment(Qt::AlignLeft);
    m_pOnline_3->setAlignment(Qt::AlignVCenter);
    m_pOnline_3->setAttribute(Qt::WA_TransparentForMouseEvents);

    QHBoxLayout *KylinOnline_I = new QHBoxLayout;
    KylinOnline_I->setMargin(0);
    KylinOnline_I->setSpacing(0);
    KylinOnline_I->addSpacing(0);
    KylinOnline_I->addWidget(m_pOnline_1);
    KylinOnline_I->addSpacing(3);
    KylinOnline_I->addWidget(m_pOnline_2);
    KylinOnline_I->addStretch();

    QVBoxLayout *KylinOnline_II = new QVBoxLayout;
    KylinOnline_II->setMargin(0);
    KylinOnline_II->setSpacing(0);
    KylinOnline_II->addSpacing(0);
    KylinOnline_II->addLayout(KylinOnline_I);
    KylinOnline_II->addSpacing(4);
    KylinOnline_II->addWidget(m_pOnline_3);
    KylinOnline_II->addStretch();

    m_pOnline = new QWidget;
    m_pOnline->setFixedSize(206,88);
    m_pOnline->setLayout(KylinOnline_II);

    m_pTelphone_1 = new IconBtn("ukui-headset-symbolic");
    m_pTelphone_1->setIconSize(QSize(18,18));
    m_pTelphone_1->setFixedSize(QSize(18,18));

    m_pTelphone_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);//不响应鼠标事件，直接穿透
    m_pTelphone_1->setProperty("useIconHighlightEffect", 0x8);

    m_pTelphone_2 = new QLabel;
    m_pTelphone_2->adjustSize();
    m_pTelphone_2->setText(tr("Online"));//"在线咨询");
    m_pTelphone_2->setAlignment(Qt::AlignLeft);
    m_pTelphone_2->setAlignment(Qt::AlignVCenter);
    m_pTelphone_2->setAttribute(Qt::WA_TransparentForMouseEvents);

    m_pTelphone_3 = new QLabel;
    m_pTelphone_3->adjustSize();
    m_pTelphone_3->setText(tr("Leave message\n to get support."));//"提供IM和反馈两种在线咨询方式");
    m_pTelphone_3->setAlignment(Qt::AlignLeft);
    m_pTelphone_3->setAlignment(Qt::AlignVCenter);
    m_pTelphone_3->setAttribute(Qt::WA_TransparentForMouseEvents);

    QHBoxLayout *KylinTelphone_I = new QHBoxLayout;
    KylinTelphone_I->setMargin(0);
    KylinTelphone_I->setSpacing(0);
    KylinTelphone_I->addSpacing(0);
    KylinTelphone_I->addWidget(m_pTelphone_1);
    KylinTelphone_I->addSpacing(3);
    KylinTelphone_I->addWidget(m_pTelphone_2);
    KylinTelphone_I->addStretch();

    QVBoxLayout *KylinTelphone_II = new QVBoxLayout;
    KylinTelphone_II->setMargin(0);
    KylinTelphone_II->setSpacing(0);
    KylinTelphone_II->addSpacing(0);
    KylinTelphone_II->addLayout(KylinTelphone_I);
    KylinTelphone_II->addSpacing(4);
    KylinTelphone_II->addWidget(m_pTelphone_3);
    KylinTelphone_II->addStretch();

    m_pTelphone = new QWidget;
    m_pTelphone->setFixedSize(206,88);
    m_pTelphone->setLayout(KylinTelphone_II);

    m_pMail_1 = new IconBtn("mail-read-symbolic");
    m_pMail_1->setIconSize(QSize(18,18));
    m_pMail_1->setFixedSize(QSize(18,18));

    m_pMail_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);//不响应鼠标事件，直接穿透
    m_pMail_1->setProperty("useIconHighlightEffect", 0x8);
//    m_pMail_1->setIcon(QIcon::fromTheme("mail-read-symbolic"));

    m_pMail_2 = new QLabel;
    m_pMail_2->adjustSize();
    m_pMail_2->setText(tr("Mail"));//"邮件咨询");
    m_pMail_2->setAlignment(Qt::AlignLeft);
    m_pMail_2->setAlignment(Qt::AlignVCenter);
    m_pMail_2->setAttribute(Qt::WA_TransparentForMouseEvents);

    m_pMail_3 = new QLabel;
    m_pMail_3->adjustSize();
    m_pMail_3->setText(tr("Send mail to\nget support."));//"用户通过发送邮件到指定官方邮件，寻\n求服务与技术响应");
    m_pMail_3->setAlignment(Qt::AlignLeft);
    m_pMail_3->setAlignment(Qt::AlignVCenter);
    m_pMail_3->setAttribute(Qt::WA_TransparentForMouseEvents);

    QHBoxLayout *KylinMail_I = new QHBoxLayout;
    KylinMail_I->setMargin(0);
    KylinMail_I->setSpacing(0);
    KylinMail_I->addSpacing(0);
    KylinMail_I->addWidget(m_pMail_1);
    KylinMail_I->addSpacing(3);
    KylinMail_I->addWidget(m_pMail_2);
    KylinMail_I->addStretch();

    QVBoxLayout *KylinMail_II = new QVBoxLayout;
    KylinMail_II->setMargin(0);
    KylinMail_II->setSpacing(0);
    KylinMail_II->addSpacing(0);
    KylinMail_II->addLayout(KylinMail_I);
    KylinMail_II->addSpacing(4);
    KylinMail_II->addWidget(m_pMail_3);
    KylinMail_II->addStretch();

    m_pMail = new QWidget;
    m_pMail->setFixedSize(206,88);
    m_pMail->setLayout(KylinMail_II);

    m_pWeChat_1 = new IconBtn("call-stop-symbolic");
    m_pWeChat_1->setIconSize(QSize(18,18));
    m_pWeChat_1->setFixedSize(QSize(18,18));
    m_pWeChat_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);//不响应鼠标事件，直接穿透
    m_pWeChat_1->setProperty("useIconHighlightEffect", 0x8);
//    m_pWeChat_1->setIcon(QIcon::fromTheme("call-stop-symbolic"));

    m_pWeChat_2 = new QLabel;
    m_pWeChat_2->adjustSize();
    m_pWeChat_2->setText(tr("Telephone"));//"电话咨询");
    m_pWeChat_2->setAlignment(Qt::AlignLeft);
    m_pWeChat_2->setAlignment(Qt::AlignVCenter);
    m_pWeChat_2->setAttribute(Qt::WA_TransparentForMouseEvents);

    m_pWeChat_3 = new QLabel;
    m_pWeChat_3->adjustSize();
    m_pWeChat_3->setText(tr("5*8 hours hotline."));//"5x8小时或7x24小时呼叫中心电话支持\n响应");
    m_pWeChat_3->setAlignment(Qt::AlignLeft);
    m_pWeChat_3->setAlignment(Qt::AlignVCenter);
    m_pWeChat_3->setAttribute(Qt::WA_TransparentForMouseEvents);

    QHBoxLayout *KylinWeChat_I = new QHBoxLayout;
    KylinWeChat_I->setMargin(0);
    KylinWeChat_I->setSpacing(0);
    KylinWeChat_I->addSpacing(0);
    KylinWeChat_I->addWidget(m_pWeChat_1,1);
    KylinWeChat_I->addSpacing(3);
    KylinWeChat_I->addWidget(m_pWeChat_2,1);
    KylinWeChat_I->addStretch(99);

    QVBoxLayout *KylinWeChat_II = new QVBoxLayout;
    KylinWeChat_II->setMargin(0);
    KylinWeChat_II->setSpacing(0);
    KylinWeChat_II->addSpacing(0);
    KylinWeChat_II->addLayout(KylinWeChat_I,1);
    KylinWeChat_II->addSpacing(4);
    KylinWeChat_II->addWidget(m_pWeChat_3,1);
    KylinWeChat_II->addStretch(99);

    m_pWeChat = new QWidget;
    m_pWeChat->setFixedSize(206,88);
    m_pWeChat->setLayout(KylinWeChat_II);

    m_pDIY_1 = new IconBtn("view-paged-symbolic");
    m_pDIY_1->setIconSize(QSize(18,18));
    m_pDIY_1->setFixedSize(QSize(18,18));
    m_pDIY_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);//不响应鼠标事件，直接穿透
    m_pDIY_1->setProperty("useIconHighlightEffect", 0x8);
//    m_pDIY_1->setIcon(QIcon::fromTheme("view-paged-symbolic"));

    m_pDIY_2 = new QLabel;
    m_pDIY_2->adjustSize();
    m_pDIY_2->setText(tr("Guidance"));//"自助支持");
    m_pDIY_2->setAlignment(Qt::AlignLeft);
    m_pDIY_2->setAlignment(Qt::AlignVCenter);
    m_pDIY_2->setAttribute(Qt::WA_TransparentForMouseEvents);

    m_pDIY_3 = new QLabel;
    m_pDIY_3->adjustSize();
    m_pDIY_3->setText(tr("Check Manuals to solve\nthe problem."));//用户通过搜索和查询帮助手册、文档中\n心、FAQ内容和已排除疑问解决问题");
    m_pDIY_3->setAlignment(Qt::AlignLeft);
    m_pDIY_3->setAlignment(Qt::AlignVCenter);
    m_pDIY_3->setAttribute(Qt::WA_TransparentForMouseEvents);

    QHBoxLayout *KylinDIY_I = new QHBoxLayout;
    KylinDIY_I->setMargin(0);
    KylinDIY_I->setSpacing(0);
    KylinDIY_I->addSpacing(0);
    KylinDIY_I->addWidget(m_pDIY_1);
    KylinDIY_I->addSpacing(3);
    KylinDIY_I->addWidget(m_pDIY_2);
    KylinDIY_I->addStretch();

    QVBoxLayout *KylinDIY_II = new QVBoxLayout;
    KylinDIY_II->setMargin(0);
    KylinDIY_II->setSpacing(0);
    KylinDIY_II->addSpacing(0);
    KylinDIY_II->addLayout(KylinDIY_I);
    KylinDIY_II->addSpacing(4);
    KylinDIY_II->addWidget(m_pDIY_3);
    KylinDIY_II->addStretch();

    m_pDIY = new QWidget;
    m_pDIY->setFixedSize(206,88);
    m_pDIY->setLayout(KylinDIY_II);

    QHBoxLayout *HmainLayout_I = new QHBoxLayout;
    HmainLayout_I->addSpacing(0);
    HmainLayout_I->setMargin(0);
    HmainLayout_I->addSpacing(30);
    HmainLayout_I->addWidget(m_pOnline);
    HmainLayout_I->addSpacing(42);
    HmainLayout_I->addWidget(m_pTelphone);
    HmainLayout_I->addSpacing(42);
    HmainLayout_I->addWidget(m_pMail);
    HmainLayout_I->addStretch();

    QHBoxLayout *HmainLayout_II = new QHBoxLayout;
    HmainLayout_II->addSpacing(0);
    HmainLayout_II->setMargin(0);
    HmainLayout_II->addSpacing(30);
    HmainLayout_II->addWidget(m_pWeChat);
    HmainLayout_II->addSpacing(42);
    HmainLayout_II->addWidget(m_pDIY);
    HmainLayout_II->addStretch();

    QHBoxLayout *HmainLayout_KylinPic = new QHBoxLayout;
    HmainLayout_KylinPic->addSpacing(0);
    HmainLayout_KylinPic->setMargin(0);
    HmainLayout_KylinPic->addSpacing(30);
    HmainLayout_KylinPic->addWidget(m_pKylinPic);
    HmainLayout_KylinPic->addStretch();

    QHBoxLayout *HmainLayout_MoreInfoLink = new QHBoxLayout;
    HmainLayout_MoreInfoLink->setSpacing(0);
    HmainLayout_MoreInfoLink->setMargin(0);
    HmainLayout_MoreInfoLink->addStretch();
    HmainLayout_MoreInfoLink->addWidget(m_pMoreInfoLink_1);
    HmainLayout_MoreInfoLink->addWidget(m_pMoreInfoLink_2);
    HmainLayout_MoreInfoLink->addWidget(m_pMoreInfoLink_3);
    HmainLayout_MoreInfoLink->addSpacing(30);

    QHBoxLayout *HmainLayout_PageTitle = new QHBoxLayout;
    HmainLayout_PageTitle->addSpacing(0);
    HmainLayout_PageTitle->setMargin(0);
    HmainLayout_PageTitle->addSpacing(30);
    HmainLayout_PageTitle->addWidget(m_pPageTitle);
    HmainLayout_PageTitle->addStretch();

    QVBoxLayout *VmainLayout = new QVBoxLayout;
    VmainLayout->setSpacing(0);
    VmainLayout->setMargin(0);
    VmainLayout->addLayout(HmainLayout_KylinPic);
    VmainLayout->addSpacing(8);
    VmainLayout->addLayout(HmainLayout_MoreInfoLink);
    VmainLayout->addStretch();
    VmainLayout->addLayout(HmainLayout_PageTitle);
    VmainLayout->addStretch();
    VmainLayout->addLayout(HmainLayout_I);
    VmainLayout->addStretch();
    VmainLayout->addLayout(HmainLayout_II);
    VmainLayout->addStretch();
    this->setLayout(VmainLayout);
}
/************************************************
* 函数名称：eventFilter
* 功能描述：m_pMoreInfoLink_2点击跳转到ubuntukylin主页
* 输入参数：
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
bool MainPage::eventFilter(QObject *obj, QEvent *ev)
{
    if(obj == m_pMoreInfoLink_2)
    {
        if(ev->type() == QEvent::MouseButtonPress)
        {
            /* SDK功能点： 跳转官网主页*/
            GlobalData::SDKPointJumpOfficicalWebsite();

            QDesktopServices::openUrl(QUrl("https://www.kylinos.cn/support/problem.html"));

        }
    }

    return QWidget::eventFilter(obj,ev);
}
/************************************************
* 函数名称：changePageForTheme
* 功能描述：主题适配函数
* 输入参数：
* 输出参数：无
* 修改日期：2020.11.04
* 修改内容：
*   创建  HZH
*
*************************************************/
void MainPage::changePageForTheme(const QString& str)
{
    m_currentTheme = str;

    if("ukui-dark" == str || "ukui-black" == str)
    {
        m_pOnline_2->setStyleSheet("background-color:transparent;color:rgba(249, 249, 249, 1);");
        m_pOnline_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pTelphone_2->setStyleSheet("background-color:transparent;color:rgba(249, 249, 249, 1);");
        m_pTelphone_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pMail_2->setStyleSheet("background-color:transparent;color:rgba(249, 249, 249, 1);");
        m_pMail_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pWeChat_2->setStyleSheet("background-color:transparent;color:rgba(249, 249, 249, 1);");
        m_pWeChat_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pDIY_2->setStyleSheet("background-color:transparent;color:rgba(249, 249, 249, 1);");
        m_pDIY_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

    }
    else
    {
        m_pOnline_2->setStyleSheet("background-color:transparent;color:rgba(48, 49, 51, 1);");
        m_pOnline_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pTelphone_2->setStyleSheet("background-color:transparent;color:rgba(48, 49, 51, 1);");
        m_pTelphone_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pMail_2->setStyleSheet("background-color:transparent;color:rgba(48, 49, 51, 1);");
        m_pMail_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pWeChat_2->setStyleSheet("background-color:transparent;color:rgba(48, 49, 51, 1);");
        m_pWeChat_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

        m_pDIY_2->setStyleSheet("background-color:transparent;color:rgba(48, 49, 51, 1);");
        m_pDIY_3->setStyleSheet("background-color:transparent;color:rgba(143, 147, 153, 1);");

    }
}

void MainPage::changeFont(QFont curFont)
{
    double smallFontSize = (static_cast<double>(curFont.pointSizeF())/14)*12;
    QFont smallFont;
    smallFont.setPointSizeF(smallFontSize);
    QFont normalFont = curFont;
    //小字
    m_pMoreInfoLink_1->setFont(smallFont);
    m_pMoreInfoLink_2->setFont(smallFont);
    m_pMoreInfoLink_3->setFont(smallFont);
    m_pPageTitle->setFont(smallFont);
    m_pOnline_3->setFont(smallFont);
    m_pTelphone_3->setFont(smallFont);
    m_pMail_3->setFont(smallFont);
    m_pWeChat_3->setFont(smallFont);
    m_pDIY_3->setFont(smallFont);
    //中等字
    m_pOnline_2->setFont(normalFont);
    m_pTelphone_2->setFont(normalFont);
    m_pMail_2->setFont(normalFont);
    m_pWeChat_2->setFont(normalFont);
    m_pDIY_2->setFont(normalFont);
}
